{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "051336e7-a95c-473a-af92-8eff46d7fcdc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入中国电话号码： 13228190939\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13228190939 是有效的电话号码格式吗？ False\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入中国邮政编码： 200403566\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200403566 是有效的邮政编码格式吗？ False\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入网站网址： www.baidu.com\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "www.baidu.com 是有效的网站网址格式吗？ False\n"
     ]
    }
   ],
   "source": [
    "import os, re\n",
    "def check_phone(strPhone): #中华人民共和国电话号码\n",
    "    regex_phone = re.compile(r'^(\\(\\d{3}\\)|\\d{3}-)?\\d{8}$')\n",
    "    result = True if regex_phone.match(strPhone) else False\n",
    "    return result\n",
    "def check_ZIP(strZIP):     #中华人民共和国邮政编码\n",
    "    regex_ZIP = re.compile(r'^\\d{6}$')\n",
    "    result = True if regex_ZIP.match(strZIP) else False\n",
    "    return result\n",
    "def check_URL(strURL):     #网站网址\n",
    "    regex_URL = re.compile(r'^https?://\\w+(?:\\.[^\\.]+)+(?:/.+)*$')\n",
    "    result = True if regex_URL.match(strURL) else False\n",
    "    return result\n",
    "def check_email(strEmail):#email地址\n",
    "    regex_email = re.compile(r'^[\\w\\.\\-]+@([\\w\\-]+\\.)+[\\w\\-]+$')\n",
    "    result = True if regex_email.match(strEmail) else False\n",
    "    return result\n",
    "#测试代码\n",
    "if __name__=='__main__':\n",
    "    str1 = input(\"请输入中国电话号码：\")\n",
    "    print(str1,'是有效的电话号码格式吗？', check_phone(str1))\n",
    "    str2 = input(\"请输入中国邮政编码：\")\n",
    "    print(str2,'是有效的邮政编码格式吗？', check_ZIP(str2))\n",
    "    str3 = input(\"请输入网站网址：\")    \n",
    "    print(str3,'是有效的网站网址格式吗？', check_URL(str3))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aad15de4-7256-47d0-8416-9136587c2157",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
